const a = function ({ row, column, rowIndex, data }) {
  const fields = ["DEPT_NAME", "PROGRAM_NAME_1", "PROGRAM_NAME_2"];
  const property = column.property;
  let rowspan = 1;
  let colspan = 1;
  if (fields.includes(property)) {
    if (property !== "PROGRAM_NAME_2") {
      if (rowIndex > 0 && data[rowIndex - 1][property] === row[property]) {
        rowspan = 0;
      } else {
        for (let i = rowIndex + 1; i < data.length; i++) {
          if (data[i][property] === row[property]) {
            rowspan++;
          } else {
            break;
          }
        }
      }
    }

    const nameValue = row.DEPT_NAME;
    const pName1Value = row.PROGRAM_NAME_1;
    const pName2Value = row.PROGRAM_NAME_2;
    if (nameValue === pName1Value && pName1Value === pName2Value) {
      if (property === "DEPT_NAME") {
        colspan = 3;
      } else {
        colspan = 0;
      }
    } else if (pName1Value === pName2Value) {
      if (property === "PROGRAM_NAME_1") {
        colspan = 2;
      } else if (property === "PROGRAM_NAME_2") {
        colspan = 0;
      }
    }
  }
  return {
    rowspan,
    colspan,
  };
};

const data = [
  {
    DEPT_NAME: "1",
    PROGRAM_NAME_1: "1",
    PROGRAM_NAME_2: "3",
  },
  {
    DEPT_NAME: "1",
    PROGRAM_NAME_1: "1",
    PROGRAM_NAME_2: "3",
  },
  {
    DEPT_NAME: "2",
    PROGRAM_NAME_1: "2",
    PROGRAM_NAME_2: "2",
  },
  {
    DEPT_NAME: "2",
    PROGRAM_NAME_1: "2",
    PROGRAM_NAME_2: "2",
  },
];

const a1 = function ({ row, column, rowIndex, columnIndex, data }) {
  const keys = ["DEPT_NAME", "PROGRAM_NAME_1", "PROGRAM_NAME_2"];
  if (keys.includes(column.property)) {
    // 判断是否为行合并的起始位置
    if (
      rowIndex === 0 ||
      row[column.property] !== data[rowIndex - 1][column.property]
    ) {
      let rowspan = 1;
      let colspan = 1;
      // 计算行合并的行数
      for (let i = rowIndex + 1; i < data.length; i++) {
        if (row[column.property] === data[i][column.property]) {
          rowspan++;
        } else {
          break;
        }
      }
      // 计算列合并的列数
      for (let j = columnIndex + 1; j < this.columns.length; j++) {
        if (row[column.property] === data[rowIndex][this.columns[j].property]) {
          colspan++;
        } else {
          break;
        }
      }
      return {
        rowspan: rowspan,
        colspan: colspan,
      };
    } else {
      return {
        rowspan: 0,
        colspan: 0,
      };
    }
  }
};
